package com.zzedu.controller;

import com.zzedu.common.annotation.Log;
import com.zzedu.common.core.controller.BaseController;
import com.zzedu.common.core.domain.AjaxResult;
import com.zzedu.common.core.page.TableDataInfo;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.common.enums.UserTypeEnumns;
import com.zzedu.common.utils.SecurityUtils;
import com.zzedu.common.utils.ServletUtils;
import com.zzedu.common.utils.poi.ExcelUtil;
import com.zzedu.domain.ZzAppDeviceBindCode;
import com.zzedu.dto.ZzAppDeviceBindCodeDTO;
import com.zzedu.service.IZzAppDeviceBindCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * (教育-学校)设备绑定codeController
 *
 * @author Mr.Wang
 * @date 2025-06-02
 */
@RestController
@RequestMapping("/school/bindcode")
public class ZzAppDeviceBindCodeController extends BaseController {
    @Autowired
    private IZzAppDeviceBindCodeService zzAppDeviceBindCodeService;

    /**
     * 查询(教育-学校)设备绑定code列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('school:bindcode:query')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody ZzAppDeviceBindCodeDTO zzAppDeviceBindCode) {
        return getDataTable(zzAppDeviceBindCodeService.page(zzAppDeviceBindCode.getPageDTO(), zzAppDeviceBindCodeService.buildQuery(zzAppDeviceBindCode)));
    }

    /**
     * 导出(教育-学校)设备绑定code列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('school:bindcode:export')")
    @Log(title = "(教育-学校)设备绑定code", businessType = BusinessType.EXPORT)
    @RequestMapping("/export")
    public void export(ZzAppDeviceBindCodeDTO zzAppDeviceBindCode) {
        List<ZzAppDeviceBindCode> list = zzAppDeviceBindCodeService.list(zzAppDeviceBindCodeService.buildQuery(zzAppDeviceBindCode));
        ExcelUtil<ZzAppDeviceBindCode> util = new ExcelUtil<ZzAppDeviceBindCode>(ZzAppDeviceBindCode.class);
        util.exportExcel(ServletUtils.getResponse(), list, "(教育-学校)设备绑定code数据");
    }


    /**
     * 新增保存(教育-学校)设备绑定code
     */
    @PreAuthorize("@permission.hasAnyPermissions('school:bindcode:add')")
    @Log(title = "(教育-学校)设备绑定code", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult addSave() {
        UserTypeEnumns userTypeEnumns = UserTypeEnumns.getCode(SecurityUtils.getSysUser().getUserType());
        Assert.isTrue(UserTypeEnumns.SCHOOL == userTypeEnumns, "无此访问权限");
        return AjaxResult.success(zzAppDeviceBindCodeService.getCode());
    }


    /**
     * 获取(教育-学校)设备绑定code详细信息
     */
    @PreAuthorize("@permission.hasAnyPermissions('school:bindcode:query')")
    @RequestMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(zzAppDeviceBindCodeService.getById(id));
    }


}
